#!/usr/bin/python
#extract labels from dockable database file


import sys, string, os

#Name of file_list
file_list = sys.argv[1]

#Name of label_file
label = sys.argv[2]

family = 'false'


file_list_file = open(file_list, 'r')
label_file = open(label, 'r')

dict ={}

for i in label_file.readlines():
#  print i
  label, name = string.split(i,'\t')
  if len(name) > 40:
    name = name[0:40]
  dict[label] = name
  

for i in file_list_file.readlines():

   db = open(i[0:-1], 'r')
   db_lab =  open('lables_' + i[0:-1], 'w')
   print "processing file " + i
   for i in db.readlines():
     if family == 'true':
        label = 'MFCD' + string.strip(i[48:57])
        #die naechste ZEile muss richtig formatiert werden
        i = string.ljust( string.strip(dict[label]), 47) + string.strip(i) + '\n'
        family = 'false'
#     print i[0:5]
     if i[0:6] =='Family':
        family = 'true'
     db_lab.write(i)
      
   db_lab.close()
   db.close()

          
        
 


file_list_file.close()

